
package com.joolun.cloud.pay.api.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.joolun.cloud.common.core.constant.CacheConstants;
import com.joolun.cloud.pay.common.entity.PayConfig;
import com.joolun.cloud.pay.api.mapper.PayConfigMapper;
import com.joolun.cloud.pay.api.service.PayConfigService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * 支付配置
 *
 * @author www.joolun.com
 * @date 2020-05-29 16:37:13
 */
@Service
public class PayConfigServiceImpl extends ServiceImpl<PayConfigMapper, PayConfig> implements PayConfigService {

	@Override
	@Cacheable(value = CacheConstants.PAY_CONFIC_APP_ID_CACHE, key = "#appId", unless = "#result == null")
	public PayConfig findByAppId(String appId) {
		return baseMapper.findByAppId(appId);
	}

	@Override
	@Cacheable(value = CacheConstants.PAY_CONFIC_ID_CACHE, key = "#id", unless = "#result == null")
	public PayConfig getById(Serializable id) {
		return baseMapper.selectById(id);
	}

	@Override
	@Caching(evict={
			@CacheEvict(value = CacheConstants.PAY_CONFIC_ID_CACHE, allEntries = true),
			@CacheEvict(value = CacheConstants.PAY_CONFIC_APP_ID_CACHE, allEntries = true)
	})
	public boolean updateById(PayConfig entity) {
		baseMapper.updateById(entity);
		return Boolean.TRUE;
	}

	@Override
	@Caching(evict={
			@CacheEvict(value = CacheConstants.PAY_CONFIC_ID_CACHE, allEntries = true),
			@CacheEvict(value = CacheConstants.PAY_CONFIC_APP_ID_CACHE, allEntries = true)
	})
	public boolean removeById(Serializable id) {
		baseMapper.deleteById(id);
		return Boolean.TRUE;
	}
}
